import Vue from 'vue'
import axiosWrap from 'axios'

axiosWrap.defaults.timeout = 5000;
axiosWrap.interceptors.request.use(function (config) {
  Vue.prototype.$loading.show();
  return config;
}, function (error) {
  return Promise.reject(error)
});
axiosWrap.interceptors.response.use(function (response) {
  Vue.prototype.$loading.hide();
  if (typeof response.data == "string") {
    try {
      response.data = JSON.parse(response.data)
    } catch (e) {
      console.log(e)
    }
  }
  return response
}, function (error) {
  Vue.prototype.$loading.hide();
  return Promise.reject(error)
});

export default axiosWrap
